<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      function calculateArcLength(r, theta1, theta2) {
        // 将角度从度转换为弧度
        let radianTheta1 = theta1 * (Math.PI / 180);
        let radianTheta2 = theta2 * (Math.PI / 180);

        // 计算两个角度之间的差异
        let angleDifference = Math.abs(radianTheta2 - radianTheta1);

        // 如果角度跨越了360度，则调整角度差
        if (angleDifference > Math.PI) {
          angleDifference = 2 * Math.PI - angleDifference;
        }

        // 计算弧长
        let arcLength = r * angleDifference;

        return arcLength;
      }

      // 示例：假设半径为5，起始角度为0度，终止角度为90度
      let radius = 100;
      let startAngle = 0; // θ1
      let endAngle = 120; // θ2

      console.log(calculateArcLength(radius, startAngle, endAngle));
    </script>
  </body>
</html>
